<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .father {
        width: 300px;
        height: 200px;
        background-color: aquamarine;
        position: relative;
        cursor: pointer;
      }
      .son {
        width: 200px;
        height: 100px;
        background-color: rgb(185, 47, 197);
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        cursor: pointer;
      }
    </style>
  </head>
  <body>
    <div class="father">
      father盒子
      <div class="son">son盒子</div>
    </div>
    <script>
      let father = document.querySelector(".father");
      let son = document.querySelector(".son");
      let bodyEl=  document.body
       son.addEventListener(
        "click",
        function (e) {
          alert("son子盒子");
          e.stopPropagation();//阻止冒泡
        },
        false
      );
      father.addEventListener(
        "click",
        function () {
          alert("father 父盒子");
        },
        false
      );

     
      bodyEl.addEventListener(
        "click",
        function () {
            alert("body 父盒子");
        },false)
    </script>
  </body>
</html>
